﻿using UnityEngine;
using System.Collections;
using FairyGUI;

/// <summary>
/// 公告窗口
/// </summary>
public class UINoticeWindow : UIPopupWindow {

    public UINoticeWindow()
    {
        // 加载界面
        base.Init(UIPackage.CreateObject("大厅", "系统公告").asCom);

        // 系统公告
        GComponent noticeCtrl = uiComp.GetChild("公告组件").asCom;

        // 初始化关闭按钮
        GButton closeBtn = noticeCtrl.GetChild("关闭按钮").asButton;
        closeBtn.onClick.Add(() => {
            DebugInfo.Log("关闭系统公告");

            AudioController.inst.PlayUIClickEffect();
            uiComp.RemoveFromParent();
            uiComp.Dispose();
            base.Close();
        });

        // 初始化公告文本
        GTextField textCtrl = noticeCtrl.GetChild("公告文本").asTextField;
        textCtrl.text = DataKernel.inst.noticeStr;
    }

    /// <summary>
    /// 弹出窗口
    /// </summary>
    public static void Popup()
    {
        DebugInfo.Log("打开系统公告");
        UIRootController.inst.PopupWindow(new UINoticeWindow());
    }
}
